home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / wtj007.zip / CURTAIN.ZIP / RS232.ASM
Assembly Source File  |  1992-07-24  |  11KB  |  483 lines

  1.  
  2. *************** rs232.asm (part 3) *****************
  3.  
  4. ; This code is not locked in memory.  Since it is called directly &
  5. ; not at async time - its safe for it to be swapped.
  6. VxD_CODE_SEG
  7.  
  8.  
  9. BeginProc  Com_API_Proc
  10.  
  11.         ; See if we have to convert the pointer
  12.         mov     ax, [ebp.Client_AX]
  13.         cmp     ax, FUNC_READ
  14.         je      short cap10
  15.         cmp     ax, FUNC_WRITE
  16.         je      short cap10
  17.         cmp     ax, FUNC_CALL_BACK
  18.         jne     short cap20
  19.  
  20.         ; Convert it
  21. cap10:  push    eax
  22.         mov     ax, (Client_ES SHL 8) OR Client_DX
  23.         VMMcall Map_Flat
  24.         mov     [ebp.Client_EDX], eax
  25.         pop     eax
  26.  
  27. cap20:  cmp     ax, NUM_COM_API
  28.         jae     short cap40
  29.  
  30.         ; If ComVm is set & this VM isn't it - return an error
  31.         cmp     ComVm, ebx
  32.         jne     short cap50
  33.  
  34.         ; Copy parameters
  35. cap30:  mov     ecx, [ebp.Client_ECX]
  36.         mov     edx, [ebp.Client_EDX]
  37.  
  38.         movzx   eax, ax
  39.         shl     eax, 2
  40.         call    [ComApiTabl + eax]
  41.  
  42.         ; Copy return values
  43.         mov     [ebp.Client_EAX], eax
  44.         mov     [ebp.Client_ECX], ecx
  45.         mov     [ebp.Client_EDX], edx
  46.         ret
  47.  
  48. cap40:  mov     [ebp.Client_AX], ERROR_UNKNOWN_FUNCTION
  49.         ret
  50.  
  51.         ; If ComVm is 0 AND this is an open - allow it
  52. cap50:  cmp     ComVm, 0
  53.         je      short cap70
  54. cap60:  mov     [ebp.Client_AX], ERROR_NOT_OPENED
  55.         ret
  56.  
  57. cap70:  cmp     ax, FUNC_OPEN
  58.         jne     short cap60
  59.         jmp     short cap30
  60.  
  61. EndProc  Com_API_Proc
  62.  
  63.  
  64.  
  65. ; The following are the actual functions that other apps can call.
  66. ; There are multiple ways we have to get to here but these guys do
  67. ; the actual work.
  68.  
  69. ;       Call to get use of the port
  70. ;
  71. ;       ENTRY:  EBX = VM
  72. ;       EXIT:   If we get it, AX == 0
  73. ;                 else AX == error number (! 0)
  74. ;       USES:   none
  75. ;
  76. BeginProc  ComOpen
  77.  
  78.         ; If ComVm is 0, we can take it.  If not, we fail
  79.         cmp     ComVm, 0
  80.         jne     short co10
  81.  
  82.         mov     ComVm, ebx
  83.         push    ebx
  84.         add     ebx, ComCb
  85.         or      [ebx.cdFlags], COMM_FL_OPENED
  86.         pop     ebx
  87.  
  88.         xor     ax, ax
  89.         ret
  90.  
  91. co10:   mov     ax, ERROR_IN_USE
  92.         ret
  93.  
  94. EndProc  ComOpen
  95.  
  96.  
  97. ;       Call when we are done with the port
  98. ;
  99. ;       ENTRY:  EBX = VM
  100. ;       EXIT:   AX = 0
  101. ;       USES:   none
  102. ;
  103. BeginProc  ComClose
  104.  
  105.         ; Set ComVm to 0 so others can use it
  106.         mov     ComVm, 0
  107.         mov     ComCallFunc, 0
  108.  
  109.         push    ebx
  110.         add     ebx, ComCb
  111.         and     [ebx.cdFlags], not COMM_FL_OPENED
  112.         pop     ebx
  113.  
  114.         xor     ax, ax
  115.         ret
  116.  
  117. EndProc  ComClose
  118.  
  119.  
  120. ;       Call to read from the port.  It will read up to the
  121. ;       number of bytes requested but only if the status
  122. ;       bytes did not change from byte to byte.
  123. ;
  124. ;       If there is a change, it will read up to and including
  125. ;       the first changed one.
  126. ;
  127. ;       ENTRY:  ECX = Number of bytes to read
  128. ;               EDX = buffer to copy to
  129. ;       EXIT:   If no status changes, AX = 0
  130. ;                 else, AX = error value
  131. ;               ECX = Number of bytes actually read
  132. ;               EDX =   high 8 bits: byte 1 line status
  133. ;                       next 8 bits: byte 1 modem status
  134. ;                       next 8 bits: byte n line status
  135. ;                        low 8 bits: byte n modem status
  136. ;       USES:   none
  137. ;
  138. BeginProc  ComRead
  139.  
  140.         mov     edi, edx
  141.         push    ecx
  142.  
  143.         ; Read the bytes - we copy it one byte at a time
  144.         ; and check to see if we wrap & if we still have
  145.         ; room.  Because we have to check the status bytes
  146.         ; one each byte - we can't do a rep movs
  147.  
  148.         mov     esi, pInRead
  149.         mov     dx, [esi]
  150.         shl     dx, 16
  151.         mov     dx, [esi]
  152.  
  153.         ; We are done if esi == pInWrite
  154. cr10:   cmp     esi, pInWrite
  155.         je      short cr30
  156.  
  157.         ; Did the status change?
  158.         cmp     [esi], dx
  159.         jne     short cr50                      ; status change
  160.         inc     esi                             ; No - get it
  161.         inc     esi
  162.         movsb                                   ; Saved it
  163.  
  164.         ; Did we wrap?
  165.         cmp     esi, offset32 InBuf + BUF_SIZE
  166.         jae     short cr40
  167.  
  168. cr20:   loop    cr10
  169.  
  170. cr30:   mov     pInRead, esi                    ; Save new pointer
  171.         pop     eax
  172.         sub     eax, ecx
  173.         mov     ecx, eax
  174.         xor     ax, ax
  175.         ret
  176.  
  177. cr40:   mov     esi, offset32 InBuf
  178.         jmp     short cr20
  179.  
  180.         ; We had a status change
  181. cr50:   lodsw
  182.         mov     dx, ax
  183.         movsb
  184.         dec     cx
  185.         cmp     esi, offset32 InBuf + BUF_SIZE
  186.         jb      short cr30
  187.         mov     esi, offset32 InBuf
  188.         jmp     short cr30
  189.  
  190. EndProc  ComRead
  191.  
  192.  
  193. ;       Call to write n bytes to the port
  194. ;
  195. ;       ENTRY:  ECX = number of bytes to write
  196. ;               EDX = buffer to write from
  197. ;       EXIT:   if ok, AX = 0
  198. ;                 else AX = error
  199. ;               ECX = bytes written
  200. ;       USES:   EAX, EDX, EDI, ESI
  201. ;
  202. BeginProc  ComWrite
  203.  
  204.         mov     esi, edx
  205.         push    ecx
  206.  
  207.         ; Store the bytes - we copy it one byte at a time
  208.         ; and check to see if we wrap & if we still have
  209.         ; room.  A rep movsd would be better but is not
  210.         ; really relevant to VxDs & takes a lot more code.
  211.  
  212.         mov     edi, pOutWrite
  213.         mov     edx, pOutRead
  214.         dec     edx
  215.         cmp     edx, offset32 OutBuf
  216.         jae     short cw10
  217.         mov     edx, offset32 OutBuf + BUF_SIZE - 1
  218.  
  219.         ; We are done if edi == pOutRead-1 (edx)
  220. cw10:   cmp     edi, edx
  221.         je      short cw30
  222.         movsb                                   ; Saved it
  223.  
  224.         ; Did we wrap?
  225.         cmp     edi, offset32 OutBuf + BUF_SIZE
  226.         jae     short cw50
  227.  
  228. cw20:   loop    cw10
  229.  
  230. cw30:   mov     pOutWrite, edi                  ; Save new pointer
  231.  
  232.         ; How much did we write
  233.         pop     eax
  234.         sub     eax, ecx
  235.         push    eax
  236.  
  237.         ; If the transmit buffer is empty - send a byte
  238.         mov     dx, 3FDh
  239.         in      al, dx
  240.         test    al, 00100000b
  241.         jz      short cw40
  242.         call    TransmitBuf
  243.  
  244. cw40:   pop     ecx
  245.         xor     ax, ax
  246.         ret
  247.  
  248. cw50:   mov     edi, offset32 OutBuf
  249.         jmp     short cw20
  250.  
  251. EndProc  ComWrite
  252.  
  253.  
  254. ; ComSetPort & ComQueryPort deleted - download sources to get them
  255.  
  256.  
  257. ;       Set a call-back address to be called when receive
  258. ;       gets full or transmit empty
  259. ;
  260. ;       ENTRY:  EDX = call-back address
  261. ;       EXIT:   AX = 0
  262. ;       USES:   none
  263. ;
  264. BeginProc  ComCallBack
  265.  
  266.  
  267.         mov     ComCallFunc, edx
  268.  
  269.         xor     ax, ax
  270.         ret
  271.  
  272. EndProc  ComCallBack
  273.  
  274.  
  275. ; Called when a VM ends - if it owns the port set the port to
  276. ; no owner.  Without this, a VM could end & still stop another
  277. ; VM from getting the port.
  278. BeginProc  ComVmTerminate
  279.  
  280.         cmp     ComVm, ebx
  281.         jne     short cvt10
  282.  
  283.         mov     ComVm, 0
  284.         mov     ComCallFunc, 0
  285.  
  286. cvt10:  clc
  287.         ret
  288.  
  289. EndProc  ComVmTerminate
  290.  
  291.  
  292. ; Set up a reasonable set of port emulation values when
  293. ; a VM is created
  294. BeginProc  ComVmCreate
  295.  
  296.         mov     eax, ebx
  297.         add     eax, ComCb
  298.         mov     [eax.bLowBaud], 60h
  299.         mov     [eax.bHiBaud], 0
  300.         mov     [eax.bIir], 0
  301.         mov     [eax.bLine], 00000111b
  302.         mov     [eax.bModem], 00001011b
  303.  
  304.         clc
  305.         ret
  306.  
  307. EndProc  ComVmCreate
  308.  
  309.  
  310. ; If we terminate an app - we reset
  311. BeginProc  ComInt21
  312.  
  313.         mov     ah, [ebp.Client_AH]
  314.         cmp     ah, 4Ch                         ; new terminate?
  315.         je      short i21_10
  316.         cmp     ah, 4Bh                         ; EXEC
  317.         je      short i21_10
  318.         cmp     ah, 31h                         ; TSR terminate?
  319.         je      short i21_10
  320.         cmp     ah, 00h                         ; old terminate?
  321.         je      short i21_10
  322.  
  323.         stc
  324.         ret
  325.  
  326. i21_10: mov     eax, ebx
  327.         add     eax, ComCb
  328.  
  329.         and     [eax.cdFlags], not COMM_FL_FAILED
  330.  
  331.         stc
  332.         ret
  333.  
  334. EndProc  ComInt21
  335.  
  336.  
  337. ; If we get an error - we reset
  338. BeginProc  ComInt23_24
  339.  
  340.         mov     eax, ebx
  341.         add     eax, ComCb
  342.  
  343.         and     [eax.cdFlags], not COMM_FL_FAILED
  344.  
  345.         stc
  346.         ret
  347.  
  348. EndProc  ComInt23_24
  349.  
  350.  
  351. VxD_CODE_ENDS
  352.  
  353.  
  354.         END
  355.  
  356.  
  357. *************** dos_call.asm *****************
  358.  
  359.  
  360. .386
  361.  
  362. IS_16   EQU     1
  363. include rs232.inc
  364.  
  365.  
  366. DGROUP  group _DATA
  367.  
  368. public  _CommRegister, _CommOpen, _CommClose, _CommRead, _CommWrite
  369. public  _CommSet, _CommQuery
  370.  
  371.  
  372. _DATA   segment dword use16 public 'DATA'
  373. assume  ds:DGROUP
  374.  
  375. CommCallAddr    dd      ?
  376.  
  377. _DATA   ends
  378.  
  379.  
  380. _TEXT   segment dword use16 public 'CODE'
  381. assume  cs:_TEXT, ds:DGROUP
  382.  
  383.  
  384. ; Gets the call address for the RS-232 VxD
  385. ; Returns 0 if no VxD
  386. _CommRegister  proc
  387.  
  388.         push    di
  389.         push    es
  390.         mov     di, 0
  391.         mov     es, di
  392.         mov     ax, 1684h
  393.         mov     bx, RS232_DEVICE_ID
  394.         int     2Fh
  395.         mov     word ptr [CommCallAddr], di
  396.         mov     word ptr [CommCallAddr+2], es
  397.  
  398.         mov     ax, es                          ; for return
  399.         or      ax, di
  400.         pop     es
  401.         pop     di
  402.         ret
  403.  
  404. _CommRegister  endp
  405.  
  406.  
  407. _CommOpen  proc
  408.  
  409.         mov     ax, FUNC_OPEN
  410.         call    dword ptr [CommCallAddr]
  411.         ret
  412.  
  413. _CommOpen  endp
  414.  
  415.  
  416. _CommClose  proc
  417.  
  418.         mov     ax, FUNC_CLOSE
  419.         call    dword ptr [CommCallAddr]
  420.         ret
  421.  
  422. _CommClose  endp
  423.  
  424.  
  425. _CommRead  proc
  426.  
  427.         push    es
  428.         push    bp
  429.         push    ax
  430.         mov     bp, sp
  431.  
  432.         mov     dx, [bp + 8]
  433.         mov     cx, [bp + 10]
  434.         push    ds
  435.         pop     es
  436.  
  437.         pop     ax
  438.         pop     bp
  439.  
  440.         mov     ax, FUNC_READ
  441.         call    dword ptr [CommCallAddr]
  442.  
  443.         pop     es
  444.         mov     ax, cx
  445.         ret
  446.  
  447. _CommRead  endp
  448.  
  449.  
  450. _CommWrite  proc
  451.  
  452.         push    es
  453.         push    bp
  454.         push    ax
  455.         mov     bp, sp
  456.  
  457.         mov     dx, [bp + 8]
  458.         mov     cx, [bp + 10]
  459.         push    ds
  460.         pop     es
  461.  
  462.         pop     ax
  463.         pop     bp
  464.  
  465.         mov     ax, FUNC_WRITE
  466.         call    dword ptr [CommCallAddr]
  467.  
  468.         pop     es
  469.         mov     ax, cx
  470.         ret
  471.  
  472. _CommWrite  endp
  473.  
  474.  
  475. ; _CommSet & _CommQuery deleted - download sources to get them
  476.  
  477.  
  478. _TEXT   ends
  479.  
  480.         end
  481.  
  482.  
  483.